home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / lib / waitnb.c < prev    next >
C/C++ Source or Header  |  1992-04-03  |  775b  |  40 lines

  1. /*  $Revision: 1.3 $
  2. **
  3. */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include "configdata.h"
  7. #include <sys/wait.h>
  8.  
  9. #if    defined(DO_USE_UNION_WAIT)
  10. typedef union wait    WAITER;
  11. #if    defined(WEXITSTATUS)
  12. #define WAITVAL(x)    (WEXITSTATUS(x))
  13. #else
  14. #define WAITVAL(x)    ((x).w_retcode)
  15. #endif    /* defined(WEXITSTATUS) */
  16. #else
  17. typedef int        WAITER;
  18. #define WAITVAL(x)    (((x) >> 8) & 0xFF)
  19. #endif    /* defined(DO_USE_UNION_WAIT) */
  20.  
  21. int
  22. waitnb(statusp)
  23.     int        *statusp;
  24. {
  25.     WAITER    w;
  26.     int        pid;
  27.  
  28. #if    defined(DO_HAVE_WAITPID)
  29.     pid = waitpid(-1, &w, WNOHANG);
  30. #endif    /* defined(DO_HAVE_WAITPID) */
  31.  
  32. #if    defined(DONT_HAVE_WAITPID)
  33.     pid = wait3(&w, WNOHANG, (struct rusage *)NULL);
  34. #endif    /* defined(DONT_HAVE_WAITPID) */
  35.  
  36.     if (pid > 0)
  37.     *statusp = WAITVAL(w);
  38.     return pid;
  39. }
  40.